package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Banji;
import com.example.exception.CustomException;
import com.example.service.BanjiService;
import com.example.vo.BanjiVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("banjiService")
public class BanjiServiceImpl extends ServiceImpl<BanjiDao, Banji> implements BanjiService {

    @Resource
    private BanjiDao banjiDao;

    public Banji add(Banji banji) {
		
	   //youquchong1
        banji.setAddtime(new Date());
        banjiDao.insert(banji);
        return banji;
    }
	
	
	
    public void delete(Long id) {
        banjiDao.deleteById(id);
    }
	

    public void update(Banji banji) {
        //youquchong2
        banjiDao.updateById(banji);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return banjiDao.daochuexcel();
    }

    @Override
    public Banji findById(Integer id) {
        return banjiDao.selectById(id);
    }

    public BanjiVo findPage(BanjiVo banjiVo) {
        LambdaQueryWrapper<Banji> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(banjiVo.getBanjimingcheng()), Banji::getBanjimingcheng,banjiVo.getBanjimingcheng());        
        Page<Banji> page = new Page<>(banjiVo.getCurrent(),banjiVo.getCurrentNum());
        banjiDao.selectPage(page,wrapper);
        List<Banji> banjis = page.getRecords();
        banjiVo.setList(banjis);
        banjiVo.setPages(page.getPages());
        banjiVo.setTotal(page.getTotal());
        banjiVo.setCurrent(page.getCurrent());
        banjiVo.setCurrentNum(page.getSize());
        return banjiVo;
    }

    @Override
    public void deleteList(List<Banji> list) {
        List<Integer> ids =  list.stream().map(Banji::getId).collect(Collectors.toList());
        banjiDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
